package net.mingsoft.statistic.action.web;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import net.mingsoft.base.entity.ResultData;
import net.mingsoft.cms.entity.ContentEntity;
import net.mingsoft.statistic.action.q.DataMapQuery;
import net.mingsoft.statistic.action.q.DataQuery;
import net.mingsoft.statistic.action.q.PubReportQuery;
import net.mingsoft.statistic.action.q.SummaryQuery;
import net.mingsoft.statistic.action.r.DataMapResponse;
import net.mingsoft.statistic.action.r.DataTable;
import net.mingsoft.statistic.action.r.SummaryResponse;
import net.mingsoft.statistic.biz.DataMapBiz;
import net.mingsoft.statistic.biz.SummaryBiz;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author genfa
 * @date 22/10/24
 */
@Api(value = "数据统计", tags = {"数据统计"})
@Controller("WebStatisticAction")
@RequestMapping("/${ms.manager.path}/cms/statistic")
public class StatisticsAction {

    @Resource
    SummaryBiz summaryBiz;

    @Resource
    DataMapBiz dataMapBiz;

    @GetMapping("/index")
    public String index(HttpServletResponse response, HttpServletRequest request){
        return "/cms/statistic/index";
    }


    @GetMapping("/map")
    public String map(HttpServletResponse response, HttpServletRequest request){
        return "/cms/statistic/map";
    }

    @ApiOperation(value = "数据总览")
    @ApiResponses(value = {
            @ApiResponse(code = 200, message = "success", response = SummaryResponse.class)
    })
    @PostMapping(value = "/summary")
    @ResponseBody
    public ResultData summary(@RequestBody SummaryQuery summaryQuery) {
        return ResultData.build().success(summaryBiz.summary(summaryQuery));
    }

    @ApiOperation(value = "已发布的报告")
    @ApiResponses(value = {
            @ApiResponse(code = 200, message = "success", response = ContentEntity.class)
    })
    @PostMapping("/report")
    @ResponseBody
    public ResultData report(@RequestBody PubReportQuery query) {
        Page<ContentEntity> page = summaryBiz.getPubList(query);
        return ResultData.build().success(page);
    }

    @ApiOperation(value = "数据地图 - 数据表_列表")
    @ApiResponses(value = {
            @ApiResponse(code = 0, message = "success", response = DataTable.class)
    })
    @PostMapping("/data-map/tables")
    @ResponseBody
    public ResultData dataMap(@RequestBody DataMapQuery query) {
        Page<DataTable> tables = dataMapBiz.tables(query);
        return ResultData.build().success(tables);
    }

    @ApiOperation(value = "数据地图 - 数据表_数据")
    @ApiResponses(value = {
            @ApiResponse(code = 0, message = "success", response = DataMapResponse.class)
    })
    @PostMapping("/data-map/data")
    @ResponseBody
    public ResultData dataMap(@RequestBody DataQuery query) {
        DataMapResponse data = dataMapBiz.data(query);
        return ResultData.build().success(data);
    }
}
